package com.lely.config;

import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.fastjson.JSON;
import com.lely.result.Response;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 自定义限流提示
 * @Author luoyong
 * @Date 2021/6/19 5:58 下午
 */
@Configuration
public class SentinelConfig {
    public SentinelConfig() {
        WebCallbackManager.setUrlBlockHandler((request, response, exception) -> {
            Response res = new Response("200", "你请求太频繁了", null);
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json");
            response.getWriter().write(JSON.toJSONString(res));
        });
    }
}
